function onShowErrorMessage() {
    var element = document.getElementById('error_description');
    if (element) {
        if (element.style.display == 'none')
            element.style.display = 'block';
        else
            element.style.display = 'none';
    }
    return true;
}

function onChangedTable(i) {
    document.getElementById('table-selection').value = i;
    return true;
}

document.getElementsByClassName=function(tagName, clsName) {
    var arr = new Array();
    var elems = document.getElementsByTagName(tagName);
    for(var cls, i = 0; (elem = elems[i]); i++ ) {
        if (elem.className == clsName)
            arr[arr.length] = elem;
    }
    return arr;
}

function checkRowSelection() {
    var arr = document.getElementsByClassName('input', 'checkbox');
    var count = 0;
    for(var i=0; i<arr.length; i++)
        if (arr[i].checked)
            count++;
    if (count != 0) {
        document.getElementById('delete').style.display = 'inline';
        if (document.getElementById('table-selection').value==1)document.getElementById('moveto').style.display = 'inline';
        if (count == 1)
            document.getElementById('edit').style.display = 'inline';
        else
            {
                document.getElementById('edit').style.display = 'none';
            }
    } else {
        document.getElementById('delete').style.display = 'none';
        document.getElementById('edit').style.display = 'none';
        document.getElementById('moveto').style.display = 'none';
    }
}

var tooltipDiv = 'message';
var d = document;
var offsetfromcursorY=15 // y offset of tooltip
var ie=d.all && !window.opera;
var ns6=d.getElementById && !d.all;
var tipobj,op;

function tooltip(el,txt) {
    tipobj=d.getElementById(tooltipDiv);
    tipobj.innerHTML = txt;
    op = 0.1;
    tipobj.style.opacity = op;
    tipobj.style.visibility="visible";
    el.onmousemove=positiontip;
    appear();
}

function hide_info(el) {
    d.getElementById(tooltipDiv).style.visibility='hidden';
    el.onmousemove='';
}

function ietruebody(){
    return (d.compatMode && d.compatMode!="BackCompat")? d.documentElement : d.body
}

function positiontip(e) {
    var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
    var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
    var winwidth=ie? ietruebody().clientWidth : window.innerWidth-20
    var winheight=ie? ietruebody().clientHeight : window.innerHeight-20
    var rightedge=ie? winwidth-event.clientX : winwidth-e.clientX;
    var bottomedge=ie? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY;
    if (rightedge < tipobj.offsetWidth)  tipobj.style.left=curX-tipobj.offsetWidth+"px";
    else tipobj.style.left=curX+"px";
    if (bottomedge < tipobj.offsetHeight) tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
    else tipobj.style.top=curY+offsetfromcursorY+"px";
}

function appear() {
    if(op < 1) {
        op += 0.1;
        tipobj.style.opacity = op;
        tipobj.style.filter = 'alpha(opacity='+op*100+')';
        t = setTimeout('appear()', 30);
    }
}


var oldClass;
function highlightTableRow(id, highlight) {
    var row = d.getElementById('row_' + id);
    if (row && row.parentNode && row.parentNode.parentNode) {
        var e = row.parentNode.parentNode;
        if (highlight) {
            if (oldClass != 'highlight')
                oldClass = e.className;
            e.className = 'highlight';
        } else {
            //alert('classname: ' + oldClass);
            e.className = oldClass;
        }
    }
}

function submitEnter(element, e) {
    var keycode;
    if (window.event)
        keycode = window.event.keyCode;
    else if (e)
        keycode = e.which;
    else return true;
    if (keycode == 13) {
        var d = document.getElementById('search2');
        if (d) 
            d.setAttribute('value', 'clicked');
        element.form.submit();
        return false;
    }
    else
        return true;
}

function checkAll(e) {
    var newCheck = true;
    if (e.checked)
        newCheck = false;
    var arr = document.getElementsByClassName('input', 'checkbox');
    for(var i=0; i<arr.length; i++)
        arr[i].checked = newCheck;
}

